package leetcode.day_2020_2021_1_25_2021_1_31;

/**
 * 11. 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
 */
public class LeetCode0011 {
    public static void main(String[] args) {
    }

    public static int maxArea1(int[] height) {
        int max = 0;
        for(int i=0; i<height.length-1; i++) {
            for(int j=i+1; j<height.length; j++) {
                int result = (j-i) * Math.min(height[i], height[j]);
                if (max < result) max = result;
            }
        }
        return max;
    }

    public static int maxArea2(int[] height) {
        // 双指针法
        int left = 0, right = height.length-1;
        int max = 0;
        while(left < right) {
            max = Math.max(max, height[left] < height[right] ? (right-left) * height[left++] : (right-left) * height[right--]);
        }
        return max;
    }
}
